<template>
        <div class="list-container">
      <div
        class="scroll-container"
        style="
          transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1);
          transition-duration: 0ms;
          transform: translate(0px, 0px) translateZ(0px);
        "
      >
        <div class="no-result" :style="{'display':(newfollowingList.totalNum?'none':'block')}"></div>
        <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      :immediate-check="false"
    >
          <van-cell class="item" v-for="data in followingList" :key="data.userId">
            <div
              class="user-avatar"
              :style="{
                backgroundImage:
                  'url(' +
                  data.avatar +
                  '?imageView2/2/w/84/h/84/format/jpg/q/100' +
                  ')',
              }"
              style="width: 42px; height: 42px"
              @click="handlerAvatar(data.userId)"
            >
            </div>
            <div class="info">
              <div class="name">{{ data.userName }}</div>
              <div class="hint">{{ data.bio?'data.bio':'这家伙很懒，什么都没有留下' }}</div>
            </div>
            <div class="follow-button tofollow" @click="handlerFollow">
              <i class="iconfont icon-add"></i>
              <span>关注</span>
            </div>
        </van-cell>
        </van-list>
      </div>
    </div>
</template>
<script>
import { onMounted, ref } from "@vue/runtime-core";
import http from "../util/http"
import { useRouter,useRoute } from "vue-router";
import { useStore } from "vuex";
export default {
    props:["myfollowName"],
  setup(props) {
    const store=useStore();
    const router=useRouter();
    const route=useRoute()
    const followingList = ref("");
    const newfollowingList =ref('')
    const handlerFollow=()=>router.push('/login')
    const handlerAvatar=(id)=>router.push(`/search/user/${id}`)
    const current=ref(1)
    const loading = ref(false);
    const finished = ref(false);
    const total=ref(0)

    onMounted(() => {
        // current.value++
      http({
        url: `/api/v1/user/${route.params.id}/${props.myfollowName}?pageIndex=1&pageSize=15`,
      }).then((res) => {
        console.log(res.data);
        followingList.value = res.data.data;
        newfollowingList.value=res.data
        total.value=res.data.totalNum
      });
    });
    const onLoad = () => {
      if (followingList.value.length === total.value &&total.value!==0) {
        finished.value = true;
        return;
      }

      console.log("到底了");
      current.value++;
      http({
        url: `/api/v1/user/${route.params.id}/${props.myfollowName}?pageIndex=${current.value}&pageSize=10`,
      }).then((res) => {
        followingList.value = [...followingList.value, ...res.data.data];
          loading.value = false;
      });
    };
    return {
      followingList,
      newfollowingList,
      handlerFollow,
      handlerAvatar,
      current,
      onLoad,
      loading,
      finished,
      total
    };
  },
  mounted() {
    this.$store.commit("hidden");
  },
  unmounted() {
    this.$store.commit("show");
  },
};
</script>

  <style lang="scss" scoped>
.van-nav-bar {
  height: 2.75rem;
  width: 100%;
  background-color: #fff;
  top: 0;
  box-sizing: border-box;
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 15%);
  position: fixed;
  left: 0;
  overflow: hidden;
  z-index: 10;

}
.list-container {
    position: absolute;
    top: 44px;
    bottom: 0;
    width: 100%;
    // overflow: hidden;
    .no-result {
      position: static;
      background-color: transparent;
      width: 100%;
      bottom: 0;
      margin: 0 auto;
      margin-top: 40px;
      padding-top: 0;
      padding-bottom: 40px;
      z-index: 9;
    }
    .van-list {
      margin: 0;
      padding: 0;
      line-height: 1.2;
      color: #262626;
      font-size: 14px;
      .item {
        height: 74px;
        position: relative;
        .user-avatar {
          position: absolute;
          top: 12px;
          border: 1px solid #e6e6e6;
          border-radius: 50%;
          background-size: cover;
          background-position: center;
          box-sizing: border-box;
        }
        .info {
          margin-left: 55px;
          margin-right: 100px;
          overflow: hidden;
          .name {
            width: 100%;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            font-size: 16px;
            margin-top: 5px;
            margin-bottom: -4px;
          }
          .hint {
            font-size: 14px;
            color: #999999;
            max-width: 100%;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
        .follow-button.tofollow {
          color: #4b8feb;
          border: 1px solid #4b8feb;
        }
        .follow-button {
          position: absolute;
          top: 17px;
          right: 15px;
          border-radius: 3px;
          width: 70px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          .icon-add {
            width: 8px;
            height: 8px;
            margin-right: 6px;
            position: relative;
            top: -1px;
          }
        }
      }
    }
  }
</style>